package VN.EDU.IMIC.DEVELOPER.LETRONGKHANH.JDBC_DEMO;

import java.sql.Connection;

import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
import com.microsoft.sqlserver.jdbc.SQLServerException;

public class DBConnection {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// Khai bao khoi tao doi tuong
		Connection objConnection;
		// Khai bao va khoi tao doi tuong trong thu vien Sqljbc4.0
		SQLServerDataSource objDataSource = new SQLServerDataSource();
		// Thiet lap tham so va cau hinh he thong
		objDataSource.setDatabaseName("DESKTOP-F43Q9GJ");
		objDataSource.setUser("sa");
		objDataSource.setPassword("12345");
		objDataSource.setDatabaseName("QLSV");
		objDataSource.setPortNumber(1433);
		// Thuc thi mo ket noi va nhan ve mot doi tuong chua thong tin ket noi
		
try {
	objConnection = objDataSource.getConnection(); 
	if(!objConnection.isClosed()){
		 System.out.println(" Ket noi thanh cong");
	}else {
		System.out.println("ket noi that bai");
	}
} catch (Exception e) {
	// TODO Auto-generated catch block
	System.out.println(e.getMessage());
}
	}

}
